﻿Imports System.IO
Partial Class WebForm_Manage_BannerUpLoad
    Inherits BasePage

    Protected Sub btnUpLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpLoad.Click
        If myFileUpload.HasFile Then
            Directory.CreateDirectory(Server.MapPath("~/upFiles/Temp"))
            Directory.CreateDirectory(Server.MapPath("~/Images") & "\backup\")
            myFileUpload.SaveAs((Server.MapPath("~/upFiles/Temp") & "\") + ActualUID + myFileUpload.FileName)
            Dim fInfo As New FileInfo((Server.MapPath("~/upFiles/Temp") & "\") + ActualUID + myFileUpload.FileName)
            If fInfo.Extension.ToUpper() = ".JPG" Then
                File.Copy(Server.MapPath("~/Images") & "\pic_indexmain.jpg", Server.MapPath("~/Images") & "\backup\" & DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "pic_indexmain.jpg")
                myFileUpload.SaveAs((Server.MapPath("~/Images") & "\pic_indexmain.jpg"))
                File.Delete(Server.MapPath("~/upFiles/Temp") & "\" + ActualUID + myFileUpload.FileName)
                Page.ClientScript.RegisterClientScriptBlock(GetType(BasePage), "StartPage", "<script language=JavaScript>  window.parent.parent.top.location='" + ResolveUrl("~/WebForm/Main/MainPage.aspx") + "';</script>")
            Else
                File.Delete(Server.MapPath("~/upFiles/Temp") & "\" + ActualUID + myFileUpload.FileName)
                ShowMessageForAjax(btnUpLoad, GetLocalResourceObject("errPicFormat"))

            End If


            '' Response.Redirect(ResolveUrl("~/WebForm/Main/MainPage.aspx") + "?Path=" + ResolveUrl("~/WebForm/Manage/BannerUpload.aspx"))
        End If
        
    End Sub
End Class
